package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);


    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> queryPage(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据id查询菜品详情
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * 删除菜品
     * @param ids
     */
    // "delete from dish where id in {ids}"
    void deleteDishByid(List<Long> ids);

    /**
     * 更新菜品信息
     * @param dish
     */
    void update(Dish dish);

    /**
     * 添加菜品信息
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 根据分类id查询菜品列表
     * @param categoryId
     * @return
     */
    List<Dish> DishListByCategoryId(Long categoryId);

    /**
     * 根据分类id查询菜品列表（菜品详情）
     * @param categoryId
     * @return
     */
    @Select("select *from dish where status=1 and category_id = #{categoryId}")
    List<DishVO> getDishesByCategoryId(Long categoryId);

    // 已经起售 、 未售卖 菜品数量统计
    Integer countByMap(Map map);
}
